<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
        /* .box{
               width: 300px;
               width: 300px;
               background-color:red;
        } */
        .html-contents {
            width: 300px;
            height: 300px;
            background-color: red;
        }
        .css-contents {
            width: 300px;
            height: 300px;
            background-color: blue;
        }
        .js-contents {
            width: 300px;
            height: 300px;
            background-color: skyblue;
        }
        .vuejs-contents {
            width: 300px;
            height: 300px;
            background-color: wheat;
        }

    </style>
</head>

<body>
    <div id="app">
        <button v-for="(item,index) in title" @click="dj(index)">
            {{item.item}}
        </button>
        <div class="box" v-bind:class="String">
               {{String}}
        </div>
        <!-- <div class="box" v-bind:class="title"></div> -->
    </div>
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
    <script>
        let vm = new Vue({
            el: "#app",
            data: {
                String:"html-contents",
                title: [{
                        item: "html",
                    },
                    {
                        item: "css",
                    },
                    {
                        item: "js",
                    },
                    {
                        item: "vuejs",
                    },
                ],

                contents: [{
                        item: "html-contents",
                    },
                    {
                        item: "css-contents",
                    },
                    {
                        item: "js-contents",
                    },
                    {
                        item: "vuejs-contents",
                    },
                ],
            },
            methods: {
                dj: function (data) {
                    this.String= this.contents[data].item
                },
            },
        });
    </script>
</body>

</html>